import { _decorator, Component, Label, Node } from 'cc';
import { Village } from '../entity/Village';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { EventManager } from '../event/EventManager';

const { ccclass, property } = _decorator;

@ccclass('ComfirmVillage')
export class ComfirmVillage extends Component {
    @property(Node)
    close:Node
    @property(Label)
    villageName:Label
    @property(Label)
    coord:Label;
    @property(Label)
    people:Label
    @property(Node)
    submit:Node

    private villageData:Village
    start() {
        this.close.on(Node.EventType.TOUCH_END, this.onClose, this)
        this.submit.on(Node.EventType.TOUCH_END, this.onSubmit, this)
    }

    setData(village:Village){
        this.villageData = village
        this.villageName.string = village.name
        this.coord.string = `( ${village.x} | ${village.y} )`
        this.people.string = village.people + ''
    }

    onClose(){
        UIManager.instance.closeUI(PrefabEnum.ComfirmVillage)
    }

    onSubmit(){
        EventManager.instance.emit(EventManager.EventType.TargetVillage, this.villageData)
        
        UIManager.instance.closeUI(PrefabEnum.SelectCoord)
        this.onClose()
    }
   
}


